#include "ChessPanelRecController.h"

ChessPanelRecController::ChessPanelRecController(QWidget *parent) {
    chessPanelRecView = new ChessPanelRecView(parent);
    gameInfos         = new QVector<GameInfo *>();

    connect(chessPanelRecView, SIGNAL(gameListIndexChangedSignal(int)), this, SLOT(gameListIndexChanged(int)));
    connect(chessPanelRecView, SIGNAL(startSimulation()), this, SIGNAL(startSimulation()), Qt::QueuedConnection);
    connect(chessPanelRecView, SIGNAL(pause()), this, SIGNAL(pause()), Qt::QueuedConnection);
    connect(chessPanelRecView, SIGNAL(resume()), this, SIGNAL(resume()), Qt::QueuedConnection);
    connect(chessPanelRecView, SIGNAL(stop()), this, SIGNAL(stop()), Qt::QueuedConnection);
}

void ChessPanelRecController::start() {
    chessPanelRecView->show();
}

void ChessPanelRecController::addGameInfo(GameInfo * info) {
    gameInfos->append(info);
    chessPanelRecView->addGameToList(info->getHeader("White") + " vs " + info->getHeader("Black"));
}

void ChessPanelRecController::gameListIndexChanged(int index) {
    chessPanelRecView->setGameInfo(gameInfos->at(index)->getHeaders());

    emit currentRecord(index);
}

ChessPanelRecController::~ChessPanelRecController() {
    delete gameInfos;
}
